Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use nvim-treesitter define_modules to attach/detach to buffers #42

Conversation

dane-harnett
Copy link
Contributor

Fixes #41

By changing the way nvim-biscuits attaches to the buffer (using the nvim-treesitter define_modules functionality)
it seems to have resolved the issue I was experiencing when opening a file via telescope.

I suspect that the BufEnter autocmd was triggering too early causing the buffer to not complete have been registered with treesitter and so the language was empty string.

@@ -140,34 +140,15 @@ nvim_biscuits.decorate_nodes = function(bufnr, lang)
end
end

nvim_biscuits.setup = function(user_config)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this function below nvim_biscuits.BufferAttach definition so that we can use it inside the setup.

local attached_buffers = {}
nvim_biscuits.BufferAttach = function(bufnr)
bufnr = bufnr or vim.api.nvim_get_current_buf()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bufnr should now be passed in.

if attached_buffers[bufnr] then return end

attached_buffers[bufnr] = true

local lang = ts_parsers.get_buf_lang(bufnr):gsub("-", "")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lang should now be passed in.

local toggle_keybind = config.get_language_config(final_config, lang,
"toggle_keybind")
if toggle_keybind ~= nil and
not config.get_language_config(final_config, lang, "disabled") then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now implemented in the is_supported function below

@@ -2,7 +2,3 @@

highlight default BiscuitColor ctermfg=gray guifg=gray

augroup NVIM_BISCUITS
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer need this.

@cmgriffing
Copy link
Contributor

Awesome. This looks great.

@cmgriffing cmgriffing merged commit 25a8806 into code-biscuits:main Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show on start doesn't work for the first file opened when opened by telescope
2 participants